﻿<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<IEnumerable<WebBags.Product>>" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Danh sách sản phẩm</title>

    <script type="text/javascript" src='<%=Url.Content("~/scripts/jquery-1.4.1.min.js")%>'></script>

    <script type="text/javascript">
        function PageNext() {
            var paging = $('#paging').val();
            var count = parseInt('<%= ViewData["intSum"] %>');
            if (count > 0) {
                $('#paging').val(parseInt(paging) + 1);
                $('#frmNav').submit();
            }
        }
        function PagePrevious() {
            var paging = $('#paging').val();
            if (parseInt(paging) > 1) {
                $('#paging').val(parseInt(paging) - 1);
                $('#frmNav').submit();
            }
        }
    </script>

</head>
<body>
    <form method="post" action='<%= Url.Action("listproduct", "admin")%>' id="frmNav">
    <input type="hidden" id="paging" name="paging" value='<%=ViewData["paging"] %>' />
    <table border="1">
        <tr>
            <th style="width: 80px">
            </th>
            <th style="width: 300px">
                Tên sản phẩm
            </th>
            <th style="width: 300px">
                Kích cở
            </th>
            <th style="width: 300px">
                Nội dung
            </th>
            <th style="width: 100px">
                Đơn giá
            </th>
            <th style="width: 100px">
                Hình ảnh
            </th>
        </tr>
        <% foreach (var item in Model)
           { %>
        <tr>
            <td>
                <%= Html.ActionLink("Sửa", "editproduct", new { id=item.ID }) %>
                |
                <%= Html.ActionLink("Xóa", "delproduct", new { id = item.ID}, new  {onclick="return confirm('Bạn có muốn xóa sản phẩm này không ?')" })%>
            </td>
            <td>
                <%= Html.Encode(item.Name_vn) %>
            </td>
            <td>
                <%= Html.Encode(item.Size_vn) %>
            </td>
            <td>
                <%= Html.Encode(item.Description_vn) %>
            </td>
            <td>
                <%= Html.Encode(item.Price) %>
            </td>
            <td>
            </td>
        </tr>
        <% } %>
    </table>
    </form>
    <div style="margin-top: 5px">
        <%
            int intTotal = (int)ViewData["intSum"];
            string pg = ViewData["paging"] != null ? ViewData["paging"].ToString() : "1";
            int intPageSize = int.Parse(ConfigurationSettings.AppSettings["PagingSize"]);
            int paging = int.Parse(pg);
            int intDu = intTotal % intPageSize;
            int intPage = intTotal / intPageSize;
            if (intDu > 0)
                intPage++;
            if (intPage > 1)
            {                    
        %>
        <%
            if (paging > 1 && paging < intPage)
            {
        %>
        <a href="javascript:PageNext();" style="float: right">
            <%=Resources.lbResources.lbNext%></a> <a href="javascript:PagePrevious();">
                <%=Resources.lbResources.lbPrevious%></a>
        <%}
            if (paging == 1 && paging < intPage)
            {                        
        %>
        <a href="javascript:PageNext();" style="float: right">
            <%=Resources.lbResources.lbNext%></a>
        <%} if (paging > 1 && paging == intPage)
            {%>
        <a href="javascript:PagePrevious();">
            <%=Resources.lbResources.lbPrevious%></a>
        <%} %>
        <%} %>
    </div>
    <div style="height: 15px">
    </div>
    <%=Html.ActionLink("Thêm","AddProduct")%>
</body>
</html>
